home *** CD-ROM | disk | FTP | other *** search
/ Champak 49 / Volume 49 - JOGO DISK .iso / Games / grabthegrub.swf / scripts / __Packages / com / mosesSupposes / fuse / FuseKitCommon.as < prev    next >
Text File  |  2007-10-01  |  17KB  |  424 lines

  1. class com.mosesSupposes.fuse.FuseKitCommon
  2. {
  3.    static var VERSION = "Fuse Kit 2.1.1 Copyright (c) 2006 Moses Gunesch, MosesSupposes.com under MIT Open Source License";
  4.    static var VERBOSE = true;
  5.    static var ALL = "ALL";
  6.    static var ALLCOLOR = "ALLCOLOR";
  7.    static var cbTicker = 0;
  8.    function FuseKitCommon()
  9.    {
  10.    }
  11.    static function _cts()
  12.    {
  13.       return "|_tint|_tintPercent|_brightness|_brightOffset|_contrast|_invertColor|_colorReset|_colorTransform|";
  14.    }
  15.    static function _resetTo100()
  16.    {
  17.       return "|_alpha|_contrast|_invertColor|_tintPercent|_xscale|_yscale|_scale|";
  18.    }
  19.    static function _resetTo0()
  20.    {
  21.       return "|_brightness|_brightOffset|_colorReset|_rotation|";
  22.    }
  23.    static function _underscoreable()
  24.    {
  25.       return com.mosesSupposes.fuse.FuseKitCommon._cts() + "_frame|_x|_y|_xscale|_yscale|_scale|_width|_height|_size|_rotation|_alpha|_fade|_visible|";
  26.    }
  27.    static function _cbprops()
  28.    {
  29.       return "|skipLevel|cycles|roundResults|extra1|extra2|func|scope|args|startfunc|startscope|startargs|updfunc|updscope|updargs|";
  30.    }
  31.    static function _fuseEvents()
  32.    {
  33.       return "|onStart|onStop|onPause|onResume|onAdvance|onComplete|";
  34.    }
  35.    static function _fuseprops()
  36.    {
  37.       return "|command|label|delay|event|eventparams|target|addTarget|trigger|startAt|ease|easing|seconds|duration|time|";
  38.    }
  39.    static function _validateFuseCommand(c, inGroup, hasArg, outputLevel, simple)
  40.    {
  41.       var _loc1_ = false;
  42.       var _loc2_ = false;
  43.       switch(c)
  44.       {
  45.          case "start":
  46.          case "stop":
  47.          case "pause":
  48.          case "resume":
  49.          case "setStartProps":
  50.             if(inGroup != true)
  51.             {
  52.                _loc1_ = true;
  53.             }
  54.             break;
  55.          case "delay":
  56.          case "trigger":
  57.             if(simple == true)
  58.             {
  59.                if(hasArg == true)
  60.                {
  61.                   _loc1_ = true;
  62.                }
  63.             }
  64.             else
  65.             {
  66.                _loc2_ = true;
  67.             }
  68.             inGroup = false;
  69.             break;
  70.          case "skipTo":
  71.             if(hasArg == true && inGroup != true)
  72.             {
  73.                _loc1_ = true;
  74.                break;
  75.             }
  76.       }
  77.       if(outputLevel > 0 && _loc1_ == false)
  78.       {
  79.          com.mosesSupposes.fuse.FuseKitCommon.error("109",c,inGroup,_loc2_);
  80.       }
  81.       return _loc1_;
  82.    }
  83.    static function output(s)
  84.    {
  85.       if(typeof com.mosesSupposes.fuse.FuseKitCommon.logOutput == "function")
  86.       {
  87.          com.mosesSupposes.fuse.FuseKitCommon.logOutput(s);
  88.       }
  89.       else
  90.       {
  91.          trace(s);
  92.       }
  93.    }
  94.    static function error(errorCode)
  95.    {
  96.       var _loc3_ = arguments[1];
  97.       var _loc4_ = arguments[2];
  98.       var _loc6_ = arguments[3];
  99.       if(com.mosesSupposes.fuse.FuseKitCommon.VERBOSE != true)
  100.       {
  101.          com.mosesSupposes.fuse.FuseKitCommon.output("[FuseKitCommon#" + errorCode + "]");
  102.          return undefined;
  103.       }
  104.       var _loc2_ = "";
  105.       var _loc5_ = "\n";
  106.       switch(errorCode)
  107.       {
  108.          case "001":
  109.             _loc2_ += "** ERROR: When using simpleSetup to extend prototypes, you must pass the Shortcuts class. **";
  110.             _loc2_ += _loc5_ + " import com.mosesSupposes.fuse.*;";
  111.             _loc2_ += _loc5_ + " ZigoEngine.simpleSetup(Shortcuts);" + _loc5_;
  112.             break;
  113.          case "002":
  114.             _loc2_ += "** ZigoEngine.doShortcut: shortcuts missing. Use the setup commands: import com.mosesSupposes.fuse.*; ZigoEngine.register(Shortcuts); **";
  115.             break;
  116.          case "003":
  117.             _loc2_ += _loc5_ + "*** Error: DO NOT use #include \"lmc_tween.as\" with this version of ZigoEngine! ***" + _loc5_;
  118.             break;
  119.          case "004":
  120.             _loc2_ += "** ZigoEngine.doTween - too few arguments [" + _loc3_ + "].";
  121.             if(Boolean(_loc4_) == true)
  122.             {
  123.                _loc2_ += " If you are trying to use Object Syntax without Fuse, pass FuseItem in your register() or simpleSetup() call. **";
  124.             }
  125.             else
  126.             {
  127.                _loc2_ += " Object syntax call failed. **";
  128.             }
  129.             break;
  130.          case "005":
  131.             _loc2_ += "** ZigoEngine.doTween - missing targets[" + _loc3_ + "] and/or props[" + _loc4_ + "] **";
  132.             break;
  133.          case "006":
  134.             _loc2_ += "** Error: easing shortcut string not recognized (\"" + _loc3_ + "\"). You may need to pass the in PennerEasing class during register or simpleSetup. **";
  135.             break;
  136.          case "007":
  137.             _loc2_ += "- ZigoEngine: Target locked [" + _loc3_ + "], ignoring tween call [" + _loc4_ + "]";
  138.             break;
  139.          case "008":
  140.             _loc2_ += "** You must register the Shortcuts class in order to use easy string-type callback parsing. **";
  141.             break;
  142.          case "009":
  143.             _loc2_ += "** ZigoEngine: A callback parameter \"" + _loc3_ + "\" was not recognized. **";
  144.             break;
  145.          case "010":
  146.             _loc2_ += "** " + (_loc3_ != true ? "FuseItem" : "ZigoEngine") + " unable to parse " + (_loc4_ != 1 ? String(_loc4_) + " callbacks[" : "callback[") + _loc6_ + "]. Try using the syntax {scope:this, func:\"myFunction\"} **";
  147.             break;
  148.          case "011":
  149.             _loc2_ += "- ZigoEngine: Callbacks discarded via skipLevel 2 option [" + _loc3_ + "|" + _loc4_ + "].";
  150.             break;
  151.          case "012":
  152.             _loc2_ += "- Engine set props or ignored no-change tween on: " + _loc3_ + ", props passed:[" + _loc4_ + "], endvals passed:[" + _loc6_ + "]";
  153.             break;
  154.          case "013":
  155.             _loc2_ += "- Engine added tween on:\n\ttargets:[" + _loc3_ + "]\n\tprops:[" + _loc4_ + "]\n\tendvals:[" + _loc6_ + "]";
  156.             break;
  157.          case "014":
  158.             _loc2_ += "** Error: easing function passed is not usable with this engine. Functions need to follow the Robert Penner model. **";
  159.             break;
  160.          case "015":
  161.             _loc2_ += "** Error: The CustomEasing class must be passed during setup (register or simpleSetup) to use custom easing Arrays. **";
  162.             break;
  163.          case "016":
  164.             _loc2_ += "[ ZigoEngine.TIME_MULTIPLIER: " + String(Number(Number(_loc3_) * 100)) + "% ]";
  165.             break;
  166.          case "101":
  167.             _loc2_ += "** ERROR: Fuse simpleSetup was removed in version 2.0! **";
  168.             _loc2_ += _loc5_ + " You must now use the following commands:";
  169.             _loc2_ += _loc5_ + _loc5_ + "\timport com.mosesSupposes.fuse.*;";
  170.             _loc2_ += _loc5_ + "\tZigoEngine.simpleSetup(Shortcuts, PennerEasing, Fuse);";
  171.             _loc2_ += _loc5_ + "Note that PennerEasing is optional, and FuseFMP is also accepted. (FuseFMP.simpleSetup is run automatically if included.)" + _loc5_;
  172.             break;
  173.          case "102":
  174.             _loc2_ += "** Fuse " + _loc3_ + " index or label not found (" + _loc4_ + ") or out of range. **";
  175.             break;
  176.          case "103":
  177.             _loc2_ += "** Fuse skipTo (" + _loc3_ + ")  ignored - targets the current index (" + _loc4_ + "). **";
  178.             break;
  179.          case "104":
  180.             _loc2_ += "** Fuse fastForward index out of play range (" + _loc3_ + ") - skipTo has been called instead. **";
  181.             break;
  182.          case "105":
  183.             _loc2_ += "** An unsupported Array method was called on Fuse. **";
  184.             break;
  185.          case "106":
  186.             _loc2_ += "** ERROR: You have not set up Fuse correctly. **";
  187.             _loc2_ += _loc5_ + "You must now use the following commands (PennerEasing is optional).";
  188.             _loc2_ += _loc5_ + "\timport com.mosesSupposes.fuse.*;";
  189.             _loc2_ += _loc5_ + "\tZigoEngine.simpleSetup(Shortcuts, PennerEasing, Fuse);" + _loc5_;
  190.             break;
  191.          case "107":
  192.             _loc2_ += "** Fuse :: id not found - Aborting open(). **";
  193.             break;
  194.          case "108":
  195.             _loc2_ += "** Fuse.startRecent: No recent Fuse found to start! **";
  196.             break;
  197.          case "109":
  198.             _loc2_ += "** Command \"" + _loc3_ + "\" discarded. ";
  199.             if(_loc4_ == true)
  200.             {
  201.                _loc2_ += "Not allowed within a group. **";
  202.             }
  203.             else if(_loc6_ == true)
  204.             {
  205.                _loc2_ += "Not supported in Object Syntax, use the " + _loc3_ + " property instead. **";
  206.             }
  207.             else
  208.             {
  209.                _loc2_ += "The command may be unrecognized or missing an argument. **";
  210.             }
  211.             break;
  212.          case "112":
  213.             _loc2_ += "** Fuse: missing com.mosesSupposes.fuse.ZigoEngine! Cannot tween. **";
  214.             break;
  215.          case "113":
  216.             _loc2_ += "** FuseItem: A callback has been discarded. Actions with a command may only contain: label, delay, scope, args. **";
  217.             break;
  218.          case "115":
  219.             _loc2_ += _loc3_ + " overlapping prop discarded: " + _loc4_;
  220.             break;
  221.          case "116":
  222.             _loc2_ += "** FuseItem Error: Delays within groups (arrays) and start/update callbacks are not supported when using Fuse without ZigoEngine. Although you need to restructure your Fuse, it should be possible to achieve the same results. **" + _loc5_;
  223.             break;
  224.          case "117":
  225.             _loc2_ += "** " + _loc3_ + ": infinite cycles are not allowed within Fuses - discarded. **";
  226.             break;
  227.          case "118":
  228.             _loc2_ += "** " + _loc3_ + ": No targets found!" + (_loc4_ != true ? "  [Skipping tween parameters in this action] **" : "  [Unable to set start props] **");
  229.             break;
  230.          case "119":
  231.             _loc2_ += "** " + _loc3_ + ": " + (_loc4_ != 1 ? _loc4_ + " actions in the group" : "") + " missing targets" + (_loc6_ != true ? " **" : " during setStartProps **");
  232.             break;
  233.          case "120":
  234.             _loc2_ += "** " + _loc3_ + ": conflict with \"" + _loc4_ + "\". Property might be doubled within a grouped-action array. **";
  235.             break;
  236.          case "121":
  237.             _loc2_ += "** Fuse timecode formatting requires \"00:\" formatting (example:\"01:01:33\" yields 61.33 seconds.) **";
  238.             break;
  239.          case "122":
  240.             _loc2_ += "** Event \"" + _loc3_ + "\" reserved by Fuse. **";
  241.             break;
  242.          case "123":
  243.             _loc2_ += "** A Fuse event parameter failed in " + _loc3_ + " **";
  244.             break;
  245.          case "124":
  246.             _loc2_ += "** " + _loc3_ + ": trigger:" + _loc4_ + " ignored - only one trigger is allowed per action **";
  247.             break;
  248.          case "125":
  249.             _loc2_ += _loc3_ + " Warning - fastForward hit an item during its tween cycle, may malfunction.";
  250.             break;
  251.          case "201":
  252.             _loc2_ += "**** FuseFMP cannot initialize argument " + _loc3_ + " (BitmapFilters cannot be applied to this object type) ****";
  253.             break;
  254.          case "202":
  255.             _loc2_ += "** FuseFMP error: A " + _loc3_ + " could not be created for " + _loc4_ + " **";
  256.             break;
  257.          case "203":
  258.             _loc2_ += "** FuseFMP.setFilterProps - too few arguments passed (" + _loc3_ + ") - minimum 2 required. **";
  259.             break;
  260.          case "204":
  261.             _loc2_ += "** FuseFMP.setFilterProps could not locate the filter passed. (" + _loc3_ + ") **";
  262.       }
  263.       com.mosesSupposes.fuse.FuseKitCommon.output(_loc2_);
  264.    }
  265.    static function parseCallback(callback, targets, outputLevel, callerIsEngine, addprefix)
  266.    {
  267.       if(callback._vcb == true)
  268.       {
  269.          return callback;
  270.       }
  271.       var validCBs = {_vcb:true,skipLevel:_global.com.mosesSupposes.fuse.ZigoEngine.SKIP_LEVEL,cycles:1};
  272.       if(callback == undefined)
  273.       {
  274.          return validCBs;
  275.       }
  276.       var cbErrors = [];
  277.       if(typeof callback == "object")
  278.       {
  279.          if(callback.skipLevel != undefined && typeof callback.skipLevel == "number" && callback.skipLevel != _global.com.mosesSupposes.fuse.ZigoEngine.SKIP_LEVEL)
  280.          {
  281.             if(callback.skipLevel >= 0 && callback.skipLevel <= 2)
  282.             {
  283.                validCBs.skipLevel = callback.skipLevel;
  284.             }
  285.          }
  286.          if(callback.cycles != undefined)
  287.          {
  288.             if(typeof callback.cycles == "number" && callback.cycles > -1)
  289.             {
  290.                validCBs.cycles = callback.cycles;
  291.             }
  292.             else if(callback.cycles.toUpperCase() == "LOOP")
  293.             {
  294.                validCBs.cycles = 0;
  295.             }
  296.          }
  297.          if(callback.extra1 != undefined)
  298.          {
  299.             validCBs.extra1 = callback.extra1;
  300.          }
  301.          if(callback.extra2 != undefined)
  302.          {
  303.             validCBs.extra2 = callback.extra2;
  304.          }
  305.          if(callback.roundResults === true || callback.roundResults === false)
  306.          {
  307.             validCBs.roundResults = callback.roundResults;
  308.          }
  309.       }
  310.       else
  311.       {
  312.          callback = {func:callback};
  313.       }
  314.       var prefixes = ["start","upd",""];
  315.       var easyfuncparse = _global.com.mosesSupposes.fuse.Shortcuts.parseStringTypeCallback;
  316.       for(var i in prefixes)
  317.       {
  318.          var prefix = prefixes[i];
  319.          var fstr = callback[prefix + "func"];
  320.          if(fstr != undefined && typeof fstr == "string" && fstr.indexOf("(") > -1)
  321.          {
  322.             if(easyfuncparse != undefined)
  323.             {
  324.                var efc = easyfuncparse(fstr);
  325.                if(efc.func != undefined)
  326.                {
  327.                   callback[prefix + "scope"] = efc.scope;
  328.                   callback[prefix + "func"] = efc.func;
  329.                   callback[prefix + "args"] = efc.args;
  330.                }
  331.             }
  332.             else if(outputLevel > 0)
  333.             {
  334.                com.mosesSupposes.fuse.FuseKitCommon.error("008");
  335.             }
  336.          }
  337.       }
  338.       var basescope = callback.scope;
  339.       for(var i in callback)
  340.       {
  341.          var fi = i.toLowerCase().indexOf("func");
  342.          if(fi > -1)
  343.          {
  344.             var prefix = i.slice(0,fi);
  345.             var func = callback[i];
  346.             var args = callback[prefix + "args"];
  347.             var scope = callback[prefix + "scope"] != undefined ? callback[prefix + "scope"] : basescope;
  348.             if(typeof func == "string" && scope[func] == undefined)
  349.             {
  350.                for(var j in targets)
  351.                {
  352.                   var targ = targets[j];
  353.                   if(typeof targ[func] == "function")
  354.                   {
  355.                      scope = targ;
  356.                      break;
  357.                   }
  358.                   if(typeof targ._parent[func] == "function")
  359.                   {
  360.                      scope = targ._parent;
  361.                      break;
  362.                   }
  363.                }
  364.                if(scope == undefined && _level0[func] != undefined)
  365.                {
  366.                   scope = _level0;
  367.                }
  368.                if(scope == undefined && _global[func] != undefined)
  369.                {
  370.                   scope = _global;
  371.                }
  372.             }
  373.             if(typeof func != "function")
  374.             {
  375.                if(typeof scope[String(func)] == "function")
  376.                {
  377.                   func = scope[String(func)];
  378.                }
  379.                else
  380.                {
  381.                   func = eval(String(func));
  382.                }
  383.             }
  384.             if(func == undefined)
  385.             {
  386.                cbErrors.push(String((addprefix != null ? addprefix + i : i) + ":" + (typeof callback[i] != "string" ? callback[i] : "\"" + callback[i] + "\"") + "/" + prefix + "scope:" + scope));
  387.             }
  388.             else
  389.             {
  390.                if(args != undefined && !(args instanceof Array))
  391.                {
  392.                   args = [args];
  393.                }
  394.                if(prefix == "")
  395.                {
  396.                   prefix = "end";
  397.                }
  398.                validCBs[prefix] = {s:scope,f:func,a:args};
  399.                if(callerIsEngine == true)
  400.                {
  401.                   validCBs[prefix].id = ++com.mosesSupposes.fuse.FuseKitCommon.cbTicker;
  402.                }
  403.                if(prefix == "start")
  404.                {
  405.                   validCBs.start.fired = false;
  406.                }
  407.             }
  408.          }
  409.          else if(com.mosesSupposes.fuse.FuseKitCommon._cbprops().indexOf("|" + i + "|") == -1)
  410.          {
  411.             com.mosesSupposes.fuse.FuseKitCommon.error("009",i);
  412.          }
  413.       }
  414.       if(cbErrors.length > 0 && outputLevel > 0)
  415.       {
  416.          if(outputLevel > 0)
  417.          {
  418.             com.mosesSupposes.fuse.FuseKitCommon.error("010",callerIsEngine,cbErrors.length,cbErrors.toString());
  419.          }
  420.       }
  421.       return validCBs;
  422.    }
  423. }
  424.